{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from pandas import DataFrame,Series\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "   Python  NumPy  Pandas\nA       1      9       9\nB       2      2       4\nC       6      7       3\nD       7      2       2\nE       3      7       1\nF       7      8       8\nH       2      2       5\nI       0      6       3\nJ       6      2       8\nK       6      0       5",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>NumPy</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>1</td>\n      <td>9</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>2</td>\n      <td>2</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>6</td>\n      <td>7</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>7</td>\n      <td>2</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>E</th>\n      <td>3</td>\n      <td>7</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>F</th>\n      <td>7</td>\n      <td>8</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>2</td>\n      <td>2</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>I</th>\n      <td>0</td>\n      <td>6</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>J</th>\n      <td>6</td>\n      <td>2</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>6</td>\n      <td>0</td>\n      <td>5</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data=np.random.randint(0, 10, size=(10,3)),\n",
    "                  index=list('ABCDEFHIJK'),\n",
    "                  columns=['Python', 'NumPy', 'Pandas'])\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "          Python      NumPy     Pandas\ncount  10.000000  10.000000  10.000000\nmean    4.000000   4.500000   4.800000\nstd     2.666667   3.205897   2.740641\nmin     0.000000   0.000000   1.000000\n25%     2.000000   2.000000   3.000000\n50%     4.500000   4.000000   4.500000\n75%     6.000000   7.000000   7.250000\nmax     7.000000   9.000000   9.000000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>NumPy</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>10.000000</td>\n      <td>10.000000</td>\n      <td>10.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>4.000000</td>\n      <td>4.500000</td>\n      <td>4.800000</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>2.666667</td>\n      <td>3.205897</td>\n      <td>2.740641</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>2.000000</td>\n      <td>2.000000</td>\n      <td>3.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>4.500000</td>\n      <td>4.000000</td>\n      <td>4.500000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>6.000000</td>\n      <td>7.000000</td>\n      <td>7.250000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>7.000000</td>\n      <td>9.000000</td>\n      <td>9.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 描述性统计\n",
    "df.describe()\n",
    "# df.describe([0.99,0.25])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "A    4.618802\nB    1.154701\nC    2.081666\nD    2.886751\nE    3.055050\nF    0.577350\nH    1.732051\nI    3.000000\nJ    3.055050\nK    3.214550\ndtype: float64"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.std()\n",
    "df.std(axis=1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "   NumPy  Pandas\nA      9       9\nB      2       4\nC      7       3\nD      2       2\nE      7       1\nF      8       8\nH      2       5\nI      6       3\nJ      2       8\nK      0       5",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>NumPy</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>A</th>\n      <td>9</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>B</th>\n      <td>2</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>C</th>\n      <td>7</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>D</th>\n      <td>2</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>E</th>\n      <td>7</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>F</th>\n      <td>8</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>H</th>\n      <td>2</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>I</th>\n      <td>6</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>J</th>\n      <td>2</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>K</th>\n      <td>0</td>\n      <td>5</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.drop(index=\"A\")\n",
    "df.drop(columns=\"Python\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n鲁班        3     8   1       0\n张三丰       5     4   9       2\n张无忌       3     9   0       6\n杜甫        9     9   9       7\n李白        9     6   6       6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>鲁班</th>\n      <td>3</td>\n      <td>8</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>张三丰</th>\n      <td>5</td>\n      <td>4</td>\n      <td>9</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>张无忌</th>\n      <td>3</td>\n      <td>9</td>\n      <td>0</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>9</td>\n      <td>9</td>\n      <td>9</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>9</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = ['鲁班', '张三丰', '张无忌', '杜甫', '李白']\n",
    "columns = ['Python', 'Java', 'H5', 'Pandas']\n",
    "data = np.random.randint(0, 10, size=(5, 4))\n",
    "\n",
    "df = pd.DataFrame(data=data, index=index, columns=columns)\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'DataFrame' object has no attribute 'unique'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mAttributeError\u001B[0m                            Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[18], line 3\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;66;03m# 去重\u001B[39;00m\n\u001B[0;32m      2\u001B[0m df[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mPython\u001B[39m\u001B[38;5;124m\"\u001B[39m]\u001B[38;5;241m.\u001B[39munique()\n\u001B[1;32m----> 3\u001B[0m \u001B[43mdf\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43munique\u001B[49m()\n",
      "File \u001B[1;32mF:\\python38\\lib\\site-packages\\pandas\\core\\generic.py:5575\u001B[0m, in \u001B[0;36mNDFrame.__getattr__\u001B[1;34m(self, name)\u001B[0m\n\u001B[0;32m   5568\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m (\n\u001B[0;32m   5569\u001B[0m     name \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_internal_names_set\n\u001B[0;32m   5570\u001B[0m     \u001B[38;5;129;01mand\u001B[39;00m name \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_metadata\n\u001B[0;32m   5571\u001B[0m     \u001B[38;5;129;01mand\u001B[39;00m name \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_accessors\n\u001B[0;32m   5572\u001B[0m     \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_info_axis\u001B[38;5;241m.\u001B[39m_can_hold_identifiers_and_holds_name(name)\n\u001B[0;32m   5573\u001B[0m ):\n\u001B[0;32m   5574\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m[name]\n\u001B[1;32m-> 5575\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mobject\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[38;5;21;43m__getattribute__\u001B[39;49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mname\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[1;31mAttributeError\u001B[0m: 'DataFrame' object has no attribute 'unique'"
     ]
    }
   ],
   "source": [
    "# 去重\n",
    "df[\"Python\"].unique()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n张三丰       5     4   9       2\n杜甫        9     9   9       7\n李白        9     6   6       6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>张三丰</th>\n      <td>5</td>\n      <td>4</td>\n      <td>9</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>9</td>\n      <td>9</td>\n      <td>9</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>9</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query(\"Python == 5\")\n",
    "df.query(\"Python >= 5\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n鲁班        3     8   1       0\n张三丰       5     4   9       2\n张无忌       3     9   0       6\n杜甫        9     9   9       7\n李白        9     6   6       6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>鲁班</th>\n      <td>3</td>\n      <td>8</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>张三丰</th>\n      <td>5</td>\n      <td>4</td>\n      <td>9</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>张无忌</th>\n      <td>3</td>\n      <td>9</td>\n      <td>0</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>9</td>\n      <td>9</td>\n      <td>9</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>9</td>\n      <td>6</td>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.query(\"Python >= 5 and Java >= 8\")\n",
    "df.query(\"Python >= 5 & Java >= 8\")\n",
    "df.query(\"Python >= 5 or Java >= 8\")\n",
    "df.query(\"Python >= 5 | Java >= 8\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n鲁班        7    20   1      50\n张三丰      28    14  17      61\n张无忌      98    45  99      85\n杜甫       23    43  29      44\n李白       32    31  16      16",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>鲁班</th>\n      <td>7</td>\n      <td>20</td>\n      <td>1</td>\n      <td>50</td>\n    </tr>\n    <tr>\n      <th>张三丰</th>\n      <td>28</td>\n      <td>14</td>\n      <td>17</td>\n      <td>61</td>\n    </tr>\n    <tr>\n      <th>张无忌</th>\n      <td>98</td>\n      <td>45</td>\n      <td>99</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>23</td>\n      <td>43</td>\n      <td>29</td>\n      <td>44</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>32</td>\n      <td>31</td>\n      <td>16</td>\n      <td>16</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = ['鲁班', '张三丰', '张无忌', '杜甫', '李白']\n",
    "columns = ['Python', 'Java', 'H5', 'Pandas']\n",
    "data = np.random.randint(0, 100, size=(5, 4))\n",
    "\n",
    "df = pd.DataFrame(data=data, index=index, columns=columns)\n",
    "df\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n鲁班        7    20   1      50\n杜甫       23    43  29      44\n李白       32    31  16      16\n张无忌      98    45  99      85\n张三丰      28    14  17      61",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>鲁班</th>\n      <td>7</td>\n      <td>20</td>\n      <td>1</td>\n      <td>50</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>23</td>\n      <td>43</td>\n      <td>29</td>\n      <td>44</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>32</td>\n      <td>31</td>\n      <td>16</td>\n      <td>16</td>\n    </tr>\n    <tr>\n      <th>张无忌</th>\n      <td>98</td>\n      <td>45</td>\n      <td>99</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>张三丰</th>\n      <td>28</td>\n      <td>14</td>\n      <td>17</td>\n      <td>61</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(ascending=False)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "data": {
      "text/plain": "     Python  Java  H5  Pandas\n张无忌      98    45  99      85\n杜甫       23    43  29      44\n李白       32    31  16      16\n鲁班        7    20   1      50\n张三丰      28    14  17      61",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Python</th>\n      <th>Java</th>\n      <th>H5</th>\n      <th>Pandas</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>张无忌</th>\n      <td>98</td>\n      <td>45</td>\n      <td>99</td>\n      <td>85</td>\n    </tr>\n    <tr>\n      <th>杜甫</th>\n      <td>23</td>\n      <td>43</td>\n      <td>29</td>\n      <td>44</td>\n    </tr>\n    <tr>\n      <th>李白</th>\n      <td>32</td>\n      <td>31</td>\n      <td>16</td>\n      <td>16</td>\n    </tr>\n    <tr>\n      <th>鲁班</th>\n      <td>7</td>\n      <td>20</td>\n      <td>1</td>\n      <td>50</td>\n    </tr>\n    <tr>\n      <th>张三丰</th>\n      <td>28</td>\n      <td>14</td>\n      <td>17</td>\n      <td>61</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by=[\"Java\",\"Python\"],ascending=False)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 5 entries, 鲁班 to 李白\n",
      "Data columns (total 4 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   Python  4 non-null      float64\n",
      " 1   Java    5 non-null      int32  \n",
      " 2   H5      5 non-null      int32  \n",
      " 3   Pandas  5 non-null      int32  \n",
      "dtypes: float64(1), int32(3)\n",
      "memory usage: 312.0+ bytes\n"
     ]
    },
    {
     "data": {
      "text/plain": "鲁班      NaN\n张三丰    28.0\n张无忌    98.0\n杜甫     23.0\n李白     32.0\nName: Python, dtype: float64"
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据信息\n",
    "df.loc[\"鲁班\",\"Python\"] = None\n",
    "df\n",
    "df.info()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "data": {
      "text/plain": "          0         1         2\n0  1.040886  1.607683 -0.251881\n1 -1.049689 -2.231091  0.757775\n2  0.690905 -1.213966 -0.039485\n3 -0.257382 -2.034603 -1.541694\n4 -1.502876 -0.988684 -0.607924",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-1.049689</td>\n      <td>-2.231091</td>\n      <td>0.757775</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.690905</td>\n      <td>-1.213966</td>\n      <td>-0.039485</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-0.257382</td>\n      <td>-2.034603</td>\n      <td>-1.541694</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>-1.502876</td>\n      <td>-0.988684</td>\n      <td>-0.607924</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(10000, 3))\n",
    "df.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "data": {
      "text/plain": "             0         1         2\n0     1.040886  1.607683  0.251881\n1     1.049689  2.231091  0.757775\n2     0.690905  1.213966  0.039485\n3     0.257382  2.034603  1.541694\n4     1.502876  0.988684  0.607924\n...        ...       ...       ...\n9995  0.171954  0.127598  0.173618\n9996  0.723559  1.111179  1.577200\n9997  0.239549  0.808938  0.786205\n9998  0.571785  0.005990  2.391956\n9999  1.387969  0.839878  0.141350\n\n[10000 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>0.251881</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1.049689</td>\n      <td>2.231091</td>\n      <td>0.757775</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.690905</td>\n      <td>1.213966</td>\n      <td>0.039485</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.257382</td>\n      <td>2.034603</td>\n      <td>1.541694</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1.502876</td>\n      <td>0.988684</td>\n      <td>0.607924</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>9995</th>\n      <td>0.171954</td>\n      <td>0.127598</td>\n      <td>0.173618</td>\n    </tr>\n    <tr>\n      <th>9996</th>\n      <td>0.723559</td>\n      <td>1.111179</td>\n      <td>1.577200</td>\n    </tr>\n    <tr>\n      <th>9997</th>\n      <td>0.239549</td>\n      <td>0.808938</td>\n      <td>0.786205</td>\n    </tr>\n    <tr>\n      <th>9998</th>\n      <td>0.571785</td>\n      <td>0.005990</td>\n      <td>2.391956</td>\n    </tr>\n    <tr>\n      <th>9999</th>\n      <td>1.387969</td>\n      <td>0.839878</td>\n      <td>0.141350</td>\n    </tr>\n  </tbody>\n</table>\n<p>10000 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.std()\n",
    "df.abs()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "outputs": [
    {
     "data": {
      "text/plain": "          0      1      2\n0     False  False  False\n1     False  False  False\n2     False  False  False\n3     False  False  False\n4     False  False  False\n...     ...    ...    ...\n9995  False  False  False\n9996  False  False  False\n9997  False  False  False\n9998  False  False  False\n9999  False  False  False\n\n[10000 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>9995</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>9996</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>9997</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>9998</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>9999</th>\n      <td>False</td>\n      <td>False</td>\n      <td>False</td>\n    </tr>\n  </tbody>\n</table>\n<p>10000 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.abs() > df.std() * 3\n",
    "cond"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [
    {
     "data": {
      "text/plain": "0       False\n1       False\n2       False\n3       False\n4       False\n        ...  \n9995    False\n9996    False\n9997    False\n9998    False\n9999    False\nLength: 10000, dtype: bool"
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cond.sum()\n",
    "cond1 = cond.any(axis=1)\n",
    "cond1"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "outputs": [
    {
     "data": {
      "text/plain": "             0         1         2\n0     1.040886  1.607683 -0.251881\n1    -1.049689 -2.231091  0.757775\n2     0.690905 -1.213966 -0.039485\n3    -0.257382 -2.034603 -1.541694\n4    -1.502876 -0.988684 -0.607924\n...        ...       ...       ...\n9995  0.171954 -0.127598 -0.173618\n9996  0.723559 -1.111179 -1.577200\n9997 -0.239549 -0.808938 -0.786205\n9998  0.571785  0.005990 -2.391956\n9999  1.387969  0.839878 -0.141350\n\n[9927 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-1.049689</td>\n      <td>-2.231091</td>\n      <td>0.757775</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.690905</td>\n      <td>-1.213966</td>\n      <td>-0.039485</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-0.257382</td>\n      <td>-2.034603</td>\n      <td>-1.541694</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>-1.502876</td>\n      <td>-0.988684</td>\n      <td>-0.607924</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>9995</th>\n      <td>0.171954</td>\n      <td>-0.127598</td>\n      <td>-0.173618</td>\n    </tr>\n    <tr>\n      <th>9996</th>\n      <td>0.723559</td>\n      <td>-1.111179</td>\n      <td>-1.577200</td>\n    </tr>\n    <tr>\n      <th>9997</th>\n      <td>-0.239549</td>\n      <td>-0.808938</td>\n      <td>-0.786205</td>\n    </tr>\n    <tr>\n      <th>9998</th>\n      <td>0.571785</td>\n      <td>0.005990</td>\n      <td>-2.391956</td>\n    </tr>\n    <tr>\n      <th>9999</th>\n      <td>1.387969</td>\n      <td>0.839878</td>\n      <td>-0.141350</td>\n    </tr>\n  </tbody>\n</table>\n<p>9927 rows × 3 columns</p>\n</div>"
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[~cond1]\n",
    "df[~cond1]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#无放回抽样\n",
    "#有放回抽样"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "outputs": [
    {
     "data": {
      "text/plain": "          0         1         2\n4 -1.502876 -0.988684 -0.607924\n3 -0.257382 -2.034603 -1.541694\n0  1.040886  1.607683 -0.251881\n1 -1.049689 -2.231091  0.757775\n2  0.690905 -1.213966 -0.039485",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>4</th>\n      <td>-1.502876</td>\n      <td>-0.988684</td>\n      <td>-0.607924</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-0.257382</td>\n      <td>-2.034603</td>\n      <td>-1.541694</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-1.049689</td>\n      <td>-2.231091</td>\n      <td>0.757775</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.690905</td>\n      <td>-1.213966</td>\n      <td>-0.039485</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df.take([1,2,3])\n",
    "df.take(np.random.permutation([0, 1, 2, 3, 4]))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "outputs": [
    {
     "data": {
      "text/plain": "          0         1         2\n0  1.040886  1.607683 -0.251881\n0  1.040886  1.607683 -0.251881\n1 -1.049689 -2.231091  0.757775\n2  0.690905 -1.213966 -0.039485\n0  1.040886  1.607683 -0.251881",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-1.049689</td>\n      <td>-2.231091</td>\n      <td>0.757775</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.690905</td>\n      <td>-1.213966</td>\n      <td>-0.039485</td>\n    </tr>\n    <tr>\n      <th>0</th>\n      <td>1.040886</td>\n      <td>1.607683</td>\n      <td>-0.251881</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 有放回抽样\n",
    "# np.random.randint(0, 10, size=10)\n",
    "df.take(np.random.randint(0, 5, size=5))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}